package com.example.pathprotectsystem.controller;

import com.example.pathprotectsystem.pojo.LushuPoint;
import com.example.pathprotectsystem.pojo.Path;
import com.example.pathprotectsystem.pojo.Point;
import com.example.pathprotectsystem.pojo.Result;
import com.example.pathprotectsystem.service.MapService;
import com.example.pathprotectsystem.service.PathService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class MapController {
    @Autowired
    private MapService mapService;
    @Autowired
    private PathService pathService;

    @GetMapping ("/getpathbyname")
    public Result<Path> getpathbyname(String name){
        System.out.println(name);
        Path p = pathService.findPathByName(name);
        return Result.success(p);
    }
    @PostMapping("/setstlnglat")
    public Result setstlnglat(@RequestBody LushuPoint lushuPoint){
        System.out.println(lushuPoint);
        Point st = lushuPoint.getStart();
        String pathName = lushuPoint.getPathName();
        mapService.setstlnglat(st,pathName);
        return Result.success();
    }
    @PostMapping("/setedlnglat")
    public Result setedlnglat(@RequestBody LushuPoint lushuPoint){
        System.out.println(lushuPoint);
        Point ed = lushuPoint.getEnd();
        String pathName = lushuPoint.getPathName();
        mapService.setedlnglat(ed,pathName);
        return Result.success();
    }
}
